﻿CREATE PROCEDURE [dbo].[AgentInsert]
	@userName		VARCHAR(8),
	@password		VARCHAR(8),
	@roleId			INT,
	@firstName		VARCHAR(50),
	@lastName		VARCHAR(50),
	@gender			CHAR(1),
	@dateOfBirth	DATE,
	@companyName	VARCHAR(50), 
	@discountRate	DECIMAL(18,2)
AS
BEGIN
	declare @customerId INT

	INSERT INTO [dbo].[Customers] ([UserName], [Password], [RoleId], [FirstName], [LastName], [Gender], [DateOfBirth])
    VALUES (@userName, @password, @roleId, @firstName, @lastName, @gender, @dateOfBirth);

    SET @customerId = CAST(IDENT_CURRENT('Customers') AS INT);

	INSERT INTO [dbo].Agents([CustomerId], [CompanyName], [DiscountRate])
	VALUES (@customerId, @companyName, @discountRate);

	SELECT @customerId AS 'CustomerId', CAST(IDENT_CURRENT('Agents') AS INT) AS 'AgentId'
END
